Ext.define('AmpleHarvest.objects.forms.irtCommon.userInformation',
{
	extend: 'Ext.form.FieldSet',
	alias: 'widget.ampleharvest-objects-forms-irtcommon-userinformation',
	title: "User Information",
	collapsible: false,
	labelWidth: 70,
	width: 620,
	boxMinWidth: 620,
	boxMinHeight: 185,
	stateful: false,
	requestorGUID: null,
	requestorSID: null,
	requestorFullName: null,
	requestorPhoneNumber: null,
	requires:
	[
			"Ext.form.field.Text", 
			"Ext.form.FieldSet",
			'Ext.layout.container.VBox',
			'Ext.layout.container.HBox',
	],
	
	setAffilationCivMil: function(bool_CivMil) {
		if(bool_CivMil){
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('supervisorsid_textfield').enable();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('supervisorsid_textfield').show();
		}else{
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('supervisorsid_textfield').hide();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('supervisorsid_textfield').disable();
		}
	},
	
	setAffilationContractor: function(bool_contractor) {
		if(bool_contractor){
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('corsid_textfield').enable();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('governmentleadsid_textfield').enable();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('corsid_textfield').show();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('governmentleadsid_textfield').show();
		}else{
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('corsid_textfield').hide();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('governmentleadsid_textfield').hide();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('corsid_textfield').disable();
			this.affilationVBox.getComponent('affilation_radiocontainer').getComponent('governmentleadsid_textfield').disable();
		}
	},
	
	setRequestorSID: function(){
		this.requestorSID = obj_config.user.userName
	},
	
	setRequestorFullName: function() {
		if(obj_config.C_STR_USER_MIDDLENAME != null ){
			this.requestorFullName = obj_config.user.firstName + ' ' + obj_config.user.middleInitial + ' ' + obj_config.user.lastName;
		} else {
			this.requestorFullName = obj_config.user.firstName + ' ' + obj_config.user.lastName;
		}
	},
	
	
	setRequestorPhoneNumber: function(){
		this.requestorPhoneNumber = obj_config.user.phone1
	},

/*
 * Used for on behalf of
 * 		
	setOnBehalfOf: function(bool_onBehalfOf){
		if(bool_onBehalfOf){
//			this.onBehalfOfUserSID.enable();
//			this.onBehalfOfUserFullName.enable();
//			this.onBehalfOfUserSecurePhone.enable();		
			this.onBehalfOfUserSID.show();
			this.onBehalfOfUserSID.allowBlank = false;
//			this.onBehalfOfUserFullName.show();
//			this.onBehalfOfUserSecurePhone.show();
		}else{
			this.onBehalfOfUserSID.hide();
			this.onBehalfOfUserSID.reset();
			this.onBehalfOfUserSID.allowBlank = true;
//			this.onBehalfOfUserFullName.hide();
//			this.onBehalfOfUserSecurePhone.hide();
//			this.onBehalfOfUserSID.disable();
//			this.onBehalfOfUserFullName.disable();
//			this.onBehalfOfUserSecurePhone.disable();
		}
	},
 *
 */
	
	initComponent: function() {
		if( this.requestorGUID == null){
			this.setRequestorSID();
			this.setRequestorFullName();
			this.setRequestorPhoneNumber();
		}
		
		this.hiddenRequestorGUID = Ext.create("Ext.form.field.Hidden", 
			{
		        name: 'user_id',
		        value: this.requestorGUID,
		        submitValue: true
		    }
		);	
		
			
		//----- Submitting user information -----//
		this.submittingUserSID = 
			Ext.create("Ext.form.field.Display", {
				fieldLabel: 'SID',
	            name: 'user_sid', //PHP Column label
	            value: this.requestorSID,
	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
	            itemId: 'sid_textfield'
			}
		);
			
		this.submittingUserFullName = 
			Ext.create("Ext.form.field.Display", {
				fieldLabel: 'Full Name',
	            name: 'user_full_name', //PHP Column label
	            value: this.requestorFullName,
	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
	            itemId: 'fullname_textfield'
			}
		);
			
		this.submittingUserSecurePhone = 
			Ext.create("Ext.form.field.Display", {
				fieldLabel: 'Phone Number (S)',
	            name: 'user_phone_number', //PHP Column label
	            value: this.requestorPhoneNumber,
	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
	            itemId: 'securephonenumber_textfield'
			}
		);

/*
 * Used for on behalf of
 * 			
		//----- On behalf of user information -----//	
		this.onBehalfOfUserSID = 
			Ext.create("Ext.form.field.Text", {
				fieldLabel: 'User SID',
				//TODO: BS - Add to REST service
	            name: 'on_behalf_of_user_sid', //PHP Column label
//	            value: '',
//	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
	            itemId: 'on_behlaf_of_sid_textfield',
//	            allowBlank : false,
                submitValue: true,
//	            disabled: true,
	            hidden: true
			}
		);

	
		this.onBehalfOfUserFullName = 
			Ext.create("Ext.form.field.Display", {
				fieldLabel: 'Full Name',
//	            name: 'user_full_name', //PHP Column label
//	            value: this.requestorFullName,
//	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
//	            itemId: 'fullname_textfield',
	            disabled: true,
	            hidden: true
			}
		);
			
		this.onBehalfOfUserSecurePhone = 
			Ext.create("Ext.form.field.Display", {
				fieldLabel: 'Phone Number (S)',
//	            name: 'user_phone_number', //PHP Column label
//	            value: this.requestorPhoneNumber,
//	            submitValue: true,
	            labelAlign: 'right',
	            labelPad: 10,
	            labelWidth: 120,
//	            itemId: 'securephonenumber_textfield',
	            disabled: true,
	            hidden: true
			}
		);
 *		
 */		
	
		/**
		 * Adds an HBox to the UserInformation fieldset
		 */		
		this.userInformationHBox = Ext.create('Ext.Panel', { 
				border: false,
				layout : 
				{
					type: 'hbox',
					align: 'top'
				}
			}
		);
		
		/**
		 * Holds the PII of the submitting user.
		 */
		this.piiVBox = Ext.create( 'Ext.Panel', {
		    border: false,
		    flex		: 1,
		    layout: 
		    {
		        type: 'vbox',
		        align: 'left'
		    },
		    items: [
	            this.hiddenRequestorGUID,
	            this.submittingUserSID, 
	            this.submittingUserFullName, 
	            this.submittingUserSecurePhone
	            
/*
 * Used for on behalf of
 * 
	            ,
	            {
	            	xtype: 'checkboxfield',
                    boxLabel  : 'On Behalf Of',
                    name: 'is_on_behalf_of', //PHP Column label
                    uncheckedValue: 'off',
                    submitValue: true,
                    handler: function(checkbox, checked) {
	            		this.up('ampleharvest-objects-forms-irtcommon-userinformation').setOnBehalfOf(checked);
	            	}
                },
	            this.onBehalfOfUserSID
//	            ,
	            this.onBehalfOfUserFullName, 
	            this.onBehalfOfUserSecurePhone
 */
            ]
		});
		
		this.affilation = Ext.create( "Ext.form.FieldSet", {
			title		: "Affilation",
			collapsible	: false,
			labelWidth	: 70,
			boxMinWidth	: 400,
			boxMinHeight: 140,
			height		: 140,
			flex		: 1.2
		});	
		
		/**
		 * Adds a VBox to the UserInformationHBox to hold the users PII and affilation information
		 */
		this.userInformationHBox.add(this.piiVBox);
		this.userInformationHBox.add(this.affilation);
		
		/**
		 * Adds a VBox to the UserInformationHBox to hold the users PII information
		 */
		this.affilation.add(
			this.affilationVBox = Ext.create('Ext.Panel', 
				{
				    border: false,
					defaultType: 'radiofield',
				    layout: 
				    {
				        type: 'vbox',
				        align: 'left'
				    },
				    items: [
					        {
					            xtype : 'checkboxgroup',
					            allowBlank : false,
					            defaultType: 'radiofield',
					            defaults: {
					                flex: 1
					            },
					            layout: 'vbox',
					            itemId: 'affilation_radiocontainer',
					            items: [
					                {
					                    boxLabel  : 'Civilian/Military',
							            name: 'user_affiliation', //PHP Column label
					                    inputValue: 'civilianmilitary',
					                    handler: function(checkbox, checked) {
					                		this.up('ampleharvest-objects-forms-irtcommon-userinformation').setAffilationCivMil(checked);
					                	}
					                }, 
					                {
					                    boxLabel  : 'Contractor',
							            name: 'user_affiliation', //PHP Column label
					                    inputValue: 'contractor',
					                    handler: function(checkbox, checked) {
					                		this.up('ampleharvest-objects-forms-irtcommon-userinformation').setAffilationContractor(checked);
					                	}
					                }, 
						            {
						            	xtype : 'textfield',
							            fieldLabel: 'Supervisor\'s SID',
							            name: 'supervisor_sid', //PHP Column label
							            hidden : true,
							            disabled: true,		
							            labelAlign: 'right',
							            labelWidth: 140,
							            itemId: 'supervisorsid_textfield',
										allowBlank	: false
						            }, 
						            {
						            	xtype : 'textfield',
							            fieldLabel: 'COR\'s SID',
							            name: 'cor_sid', //PHP Column label
							            hidden : true,
							            disabled: true,
							            labelAlign: 'right',
							            labelWidth: 140,
							            itemId: 'corsid_textfield',
										allowBlank	: false
						            }, 
						            {
						            	xtype : 'textfield',
							            fieldLabel: 'Government Lead\'s SID',
							            name: 'gov_lead_sid', //PHP Column label
							            hidden : true,
							            disabled: true,
							            labelAlign: 'right',
							            labelWidth: 140,
							            itemId: 'governmentleadsid_textfield',
										allowBlank	: false
						            }
					            ]
					        },
				            ]
				}
			));

		this.items =
		[
		 	this.userInformationHBox
		]
        this.callParent();
	}
}
);